<?php
namespace App\Http\Controllers;
use App\Libs\verificationcode\GrapVerificate;

use Illuminate\Http\Request;
class VerificateController extends Controller{

    public function __construct(Request $request){
        parent::__construct();//app('redirect')
    }
    // 获取二维码
    public function captchaImageNew(Request $request, $type = 'default'){
        $captchaUuid = generate_uuid();
        $captchaData = [
          'captchaUrl' => 'dev-api/captcha/' . $type . '/' . $captchaUuid,
          'captchaUuid' => (string)$captchaUuid
        ];
        return [
            'code' => 200,
            'msg'=>'获取成功',
            'data' => $captchaData,
        ];
      }
    //生成二维码
    public function index(Request $request,$type='default',$uid=''){
        $mode = new GrapVerificate();
        $mode->verify($uid,4,1,100,40,300);
        return '';
    }
    //验证二维码
    public function checkCaptcha(Request $request)
    {
        $captchaUuid = $request['captchaUuid'];
        $list['code'] = 200;
        $list['message'] = '验证成功';
        $model = new GrapVerificate();
        $res = $model->isVerify($captchaUuid,$request->get('captcha'));
        if (!$res) {
          $list['code'] = -1;
          $list['message'] = '验证失败';
        }
        return $list;
    }

}
